package com.elf.stepcounter;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;

import com.elf.zero.app.AbsLinearLayout;
import com.elf.zero.form.FormTextView;

public class SettingItemWidget extends AbsLinearLayout {

    private TextView tv_text, txt_value, tv_des;
    private ImageView iv_navigate;

    public SettingItemWidget(Context context) {
        super(context);
    }

    public SettingItemWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.widget_setting_item;
    }

    @Override
    protected void initView(AttributeSet attrs) {

        tv_text = findViewById(com.elf.zero.form.R.id.tv_text);
        txt_value = findViewById(com.elf.zero.form.R.id.txt_value);
        tv_des = findViewById(R.id.tv_des);
        iv_navigate = findViewById(R.id.iv_navigate);

        if (attrs != null) {
            TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SettingItemWidget);
            setText(typedArray.getString(R.styleable.SettingItemWidget_setting_text));
            setValue(typedArray.getString(R.styleable.SettingItemWidget_setting_value));
            setDes(typedArray.getString(R.styleable.SettingItemWidget_setting_des));
            showNavigate(typedArray.getBoolean(R.styleable.SettingItemWidget_setting_navigator, true));
            typedArray.recycle();
        }
    }

    public void setText(String text) {
        tv_text.setText(text);
    }

    public String getText() {
        return tv_text.getText().toString();
    }

    public void setValue(String value) {
        txt_value.setText(value);
    }

    public String getValue() {
        return txt_value.getText().toString();
    }

    public void setDes(String des) {
        tv_des.setVisibility(TextUtils.isEmpty(des) ? GONE : VISIBLE);
        tv_des.setText(des);
    }

    public String getDes() {
        return tv_des.getText().toString();
    }

    public void showNavigate(boolean b) {
        if (iv_navigate != null) {
            iv_navigate.setVisibility(b ? VISIBLE : GONE);
        }
    }
}
